app.service('chainService',['$http','$q','utilService',function($http,$q,utilService){

    this.getIndustryFullName = function($scope){
        var deferred = $q.defer();
        $http.get($scope.app.domain + '/shop/get/industry/list'
        ).then(function(reslut){
                deferred.resolve(reslut.data);
            },function(e){
                deferred.reject("连接服务器出错");
            });
        return deferred.promise;
    }

    this.getSetMealName=function($scope){
        var deferred=$q.defer();
        $http.get($scope.app.domain+'/set/meal/list/name').then(
            function(result){
            deferred.resolve(result.data);
            },function(e){
            deferred.reject("连接服务器出错");
            }
        );
        return deferred.promise;
    }

    this.findById = function($scope){
        console.info($scope.app.domain)
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'chain/'+ $scope.chainId
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    }

    this.updateSystemUserStatus = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'system/user/update/status/'+$scope.data.id,
            data:{id:$scope.data.id,status:$scope.data.status},
            method:'PUT',
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    this.updateChain = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'chain/update',
            data:$scope.chain,
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    this.updateChainShopAudit = function($scope){
        var deferred = $q.defer($scope.app.domain);
        console.info(deferred);
        utilService.api({
            url:$scope.app.domain + 'chain/merchants/audit',
            data: $scope.chain,
            method:'POST'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    this.updateChainAudit = function($scope){
        var deferred = $q.defer($scope.app.domain);
        console.info(deferred);
        utilService.api({
            url:$scope.app.domain + 'chain/audit',
            data: $scope.chain,
            method:'POST'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }


    this.findByShopId = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'shop/info/shopid/'+ $scope.shopId
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    }

    //查询预约信息
    this.checkReserve = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'goods/serve/id',
            params:{serveId:$scope.id}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    }
}]);

